package com.smitish.vueblog.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smitish.vueblog.entity.Blog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smitish.vueblog.vo.BlogUserVO;
import javafx.scene.control.Pagination;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author Smitish
 * @since 2020-11-30
 */
public interface BlogMapper extends BaseMapper<Blog> {

    /**
     * @param page 当前页码 分页显示
     * @return 返回List集合
     */
    @Select("SELECT m_blog.*,m_user.`username` FROM m_blog,m_user WHERE m_blog.user_id=m_user.id ORDER BY created DESC")
    List<BlogUserVO> getBlogUser(Page<BlogUserVO> page);

    /**
     * 删除博客
     *
     * @param id 博客ID
     * @return 返回操作结果
     */
    @Delete("DELETE FROM m_blog WHERE m_blog.id = #{blogId}")
    boolean delBolg(@Param("blogId") String id);

    /**
     * 模糊查询文章
     *
     * @param content 需要查询的内容
     * @return 返回模糊查询的结果
     */
//    @Select("SELECT * FROM m_blog WHERE content LIKE #{content} OR title LIKE #{content}")
    @Select("SELECT m_blog.*,m_user.`username` FROM m_blog,m_user WHERE m_blog.user_id=m_user.id AND content LIKE #{content}  ORDER BY created DESC")
    List<BlogUserVO> getUnknownBlog(@Param("content") String content, Page<BlogUserVO> page);


}
